﻿using System;
using System.Collections.Generic;
using System.Linq;

using Csla;

using HHB.DataAccess.Entities;

namespace HHB.Domain.Users
{
    public class UserInfo :ReadOnlyBase<UserInfo>
    {
        private static readonly PropertyInfo<int> IdProperty =
            RegisterProperty<int>(o => o.Id);

        public int Id
        {
            get { return this.GetProperty(IdProperty); }
        }

        private static readonly PropertyInfo<string> UsernameProperty =
            RegisterProperty<string>(o => o.Username);

        public string Username
        {
            get { return this.GetProperty(UsernameProperty); }
        }

        private static readonly PropertyInfo<string> LastnameProperty =
            RegisterProperty<string>(o => o.Lastname);

        public string Lastname
        {
            get { return this.GetProperty(LastnameProperty); }
        }

        private static readonly PropertyInfo<string> FirstnameProperty =
            RegisterProperty<string>(o => o.Firstname);

        public string Firstname
        {
            get { return this.GetProperty(FirstnameProperty); }
        }

        private static readonly PropertyInfo<string> PasswordProperty =
            RegisterProperty<string>(o => o.Password);

        public string Password
        {
            get { return this.GetProperty(PasswordProperty); }
        }


        internal static UserInfo Get (User entity)
        {
            return DataPortal.FetchChild<UserInfo>(entity);
        }

        private UserInfo()
        {
        }

        private void Child_Fetch(User entity)
        {
            this.LoadProperty(IdProperty, entity.Id);
            this.LoadProperty(UsernameProperty, entity.Username);
            this.LoadProperty(PasswordProperty, entity.Password);
            this.LoadProperty(LastnameProperty, entity.LastName);
            this.LoadProperty(FirstnameProperty, entity.FirstName);
        }
    }
}